---@diagnostic disable: lowercase-global, undefined-global, trailing-space

local modid = 'kukude'

local data = _require('core_'..modid..'/data/containers')

API.CONTAINER:main(data,STRINGS.MOD_KUKUDE.DRAG_HINT)



-- 动态slotbg
AddClassPostConstruct("widgets/containerwidget", function(self)
    ---用唯一标签找对应的容器ui
    ---@param unique_tag string
    ---@return class|boolean
    ---@nodiscard
    local function clientwidget(unique_tag)
        if self.container and self.container.replica.container then
            local widget = self.container.replica.container:GetWidget()
            local unique = widget and widget.unique
            if unique and unique == unique_tag then
                return widget
            end
        end
        return false
    end

    local old_Open = self.Open
    function self:Open(...)
        local res = old_Open ~= nil and {old_Open(self, ...)} or {}
        self:StartUpdating()
        return unpack(res)
    end

    local old_Close = self.Close
    function self:Close(...)
        self:StopUpdating()
        return old_Close(self, ...)
    end

    local old_OnUpdate = self.OnUpdate
    local _i = 0
    function self:OnUpdate(dt, ...)
        if TheNet:IsServerPaused() then return end
        local kkd_fleshsack = clientwidget('kkd_fleshsack')
        if kkd_fleshsack then
            _i = _i%34 + 1
            for i = 1,12 do
                self.inv[i].bgimage:SetTexture('images/slotbg/merged_img_1732977600.xml', math.floor(_i)..'.tex')
            end
        end
        return old_OnUpdate ~= nil and old_OnUpdate(self, dt, ...) or nil
    end
end)